var Util = {
    getUrlParam: function(name, url) {
        url = url == null ? window.location.href : url;
        url = url.split('#')[0];

        var reg = new RegExp('(^|\\?|&)' + name + '=([^&]*)(\\s|&|$)', 'i');
        return reg.test(url) ? RegExp.$2.replace(/\+/g, ' ').replace('null', '') : '';
    },

    format: function(fmt, date) {

        var o = {
            'M+': date.getMonth() + 1, //月份
            'd+': date.getDate(), //日
            'h+': date.getHours(), //小时
            'm+': date.getMinutes(), //分
            's+': date.getSeconds(), //秒
            'q+': Math.floor((date.getMonth() + 3) / 3), //季度
            'S': date.getMilliseconds() //毫秒
        };
        if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
        for (var k in o)
            if (new RegExp('(' + k + ')').test(fmt)) fmt = fmt.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length));
        return fmt;
    },

    /**
     * format 价格，两位小数
     * @param  {[type]} price [description]
     * @return {[type]}       [description]
     */
    formatPrice: function(price, fixed) {
        var fixed = fixed || 2;
        return (price / 100).toFixed(fixed);
    },

    dateToWeek: function(dateStr) {
        var d = new Date(dateStr);
        var week;
        switch (d.getDay()) {
            case 1:
                week = '星期一';
                break;
            case 2:
                week = '星期二';
                break;
            case 3:
                week = '星期三';
                break;
            case 4:
                week = '星期四';
                break;
            case 5:
                week = '星期五';
                break;
            case 6:
                week = '星期六';
                break;
            default:
                week = '星期天';
        }
        return week;
    }
}